import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:fate_blind_box/ui/user/edit.dart';
import 'package:fate_blind_box/utils/assets.dart';
import 'package:fate_blind_box/utils/provider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import '../../network/Api.dart';
import '../../utils/snack_bar.dart';

//个人简介
class MeIntroduce extends StatefulWidget {
  final String introduce;

  MeIntroduce(this.introduce, {Key? key}) : super(key: key);

  @override
  State<MeIntroduce> createState() => _MeIntroduceState();
}

class _MeIntroduceState extends State<MeIntroduce> {

  final TextEditingController _introdceController = TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }

  // 修改个人简介
  _getUserinfo() async {

    final res = await Api.getInstance().ModifyMeIntroduce(Provider.memberId,_introdceController.text);
    final data = res['msg'];
    ThemeSnackBar.show(context, data);
    if(res['code'] == 0){
      Navigator.pop(context, true);
      // Navigator.push(context, MaterialPageRoute(builder: (context) => const ProfileEditUi())).then((result) => setState(() {}));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(

        title: const Text('编辑简介',style: TextStyle(color: Colors.black,fontSize: 16),),
        elevation: 0,

        actions: <Widget>[
          Container(
            margin: const EdgeInsets.only(right: 15,top: 10,bottom: 10),
            height: 31,
            child: TextButton(
              style: TextButton.styleFrom(
                backgroundColor: ThemeColor.appColor,
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
                textStyle: const TextStyle(color: Colors.white),
              ),

              child: const Text('完成',style: TextStyle(color: Colors.white),),

              onPressed: () {
                _getUserinfo();
              },
            ),
          )


        ],
      ),

      body: Container(
          margin: const EdgeInsets.fromLTRB(15, 5, 15, 0),
          child: Column(
            children: [
              Container(
                  alignment: Alignment.topLeft,
                  child:Text(
                    '七天内可修改三次简介',
                    style: TextStyle(color: ThemeColor.textColorSecond,
                      fontSize: 16,
                    ),
                  )
              ),
              const SizedBox(height: 10,),
              Container(
                color: Colors.white,
                height: 200,
                child: TextField(
                  controller: _introdceController,
                  maxLength: 100,
                  maxLines: 5,
                  minLines: 2,
                  scrollPadding: const EdgeInsets.all(20),
                  style: TextStyle(
                    fontSize: 16,
                    color: ThemeColor.textColorSecond,
                  ),
                  decoration: const InputDecoration(
                    hintText: "点击填写兴趣爱好、生活方式等个人简介",
                    border: InputBorder.none,
                    contentPadding: EdgeInsets.all(20),
                  ),
                ),
              ),
            ],
          )
      ),
    );
  }
}